package com.feng.spring.hibernate.extend;

import com.feng.spring.hibernate.extend.conf.HibernateExtendConfiguration;
import com.feng.spring.hibernate.extend.core.DefaultHibernateExtendSQLBuilder;
import com.feng.spring.hibernate.extend.core.DefaultHibernateExtendSQLExecutor;
import com.feng.spring.hibernate.extend.core.HibernateExtendSQLBuilder;
import com.feng.spring.hibernate.extend.core.HibernateExtendSQLExecutor;
import com.feng.spring.hibernate.extend.dao.HibernateExtendDaoSupport;
import org.springframework.beans.factory.InitializingBean;

/**
 * 存放配置信息和hibernate sessionFactory相关信息
 */
public class HibernateExtendFactory extends HibernateExtendDaoSupport implements InitializingBean {

    private HibernateExtendConfiguration hibernateExtendConfiguration;

    private HibernateExtendSQLExecutor hibernateExtendSQLExecutor;

    private HibernateExtendSQLBuilder hibernateExtendSQLBuilder;

    public HibernateExtendConfiguration getHibernateExtendConfiguration() {
        return hibernateExtendConfiguration;
    }

    public void setHibernateExtendConfiguration(HibernateExtendConfiguration hibernateExtendConfiguration) {
        this.hibernateExtendConfiguration = hibernateExtendConfiguration;
    }

    public HibernateExtendSQLExecutor getHibernateExtendSQLExecutor() {
        return hibernateExtendSQLExecutor;
    }

    public void setHibernateExtendSQLExecutor(HibernateExtendSQLExecutor hibernateExtendSQLExecutor) {
        this.hibernateExtendSQLExecutor = hibernateExtendSQLExecutor;
    }

    public void setHibernateExtendSQLBuilder(HibernateExtendSQLBuilder hibernateExtendSQLBuilder) {
        this.hibernateExtendSQLBuilder = hibernateExtendSQLBuilder;
    }

    public HibernateExtendSQLBuilder getHibernateExtendSQLBuilder() {
        return hibernateExtendSQLBuilder;
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        if (hibernateExtendSQLExecutor == null){
            hibernateExtendSQLExecutor = new DefaultHibernateExtendSQLExecutor();
        }
        if (hibernateExtendSQLBuilder == null){
            hibernateExtendSQLBuilder = new DefaultHibernateExtendSQLBuilder();
        }
    }
}
